//
// Created by fanghr on 17-12-31.
//

#include "imu_data_parser.h"

imu_data_parser::imu_data_parser(boost::array<uint8_t, 9> arr) {
    if (arr.at(0) == 0x50) {
        imu_time tmp_time(arr);
        imu_global::imu_time_pack.lock.lock();
        imu_global::imu_time_pack.data = tmp_time;
        imu_global::imu_time_pack.lock.unlock();
    } else if (arr.at(0) == 0x51) {
        imu_acceleration tmp_acceleration(arr);
        imu_global::imu_acceleration_pack.lock.lock();
        imu_global::imu_acceleration_pack.data = tmp_acceleration;
        imu_global::imu_acceleration_pack.lock.unlock();
    } else if (arr.at(0) == 0x52) {
        imu_angularVelocity tmp_angularVelocity(arr);
        imu_global::imu_angularVelocity_pack.lock.lock();
        imu_global::imu_angularVelocity_pack.data = tmp_angularVelocity;
        imu_global::imu_angularVelocity_pack.lock.unlock();
    } else if (arr.at(0) == 0x53) {
        imu_angle tmp_angle(arr);
        imu_global::imu_angle_pack.lock.lock();
        imu_global::imu_angle_pack.data = tmp_angle;
        imu_global::imu_angle_pack.lock.unlock();
    } else if (arr.at(0) == 0x54) {
        imu_magneticOutput tmp_magneticOutput(arr);
        imu_global::imu_magneticOutput_pack.lock.lock();
        imu_global::imu_magneticOutput_pack.data = tmp_magneticOutput;
        imu_global::imu_magneticOutput_pack.lock.unlock();
    } else if (arr.at(0) == 0x55) {
        imu_portStatus tmp_portStatus(arr);
        imu_global::imu_portStatus_pack.lock.lock();
        imu_global::imu_portStatus_pack.data = tmp_portStatus;
        imu_global::imu_portStatus_pack.lock.unlock();
    } else if (arr.at(0) == 0x56) {
        imu_pressureAndHeightOutput tmp_pressureAndHeightOutput(arr);
        imu_global::imu_pressureAndHeightOutput_pack.lock.lock();
        imu_global::imu_pressureAndHeightOutput_pack.data = tmp_pressureAndHeightOutput;
        imu_global::imu_pressureAndHeightOutput_pack.lock.unlock();
    } else if (arr.at(0) == 0x57) {
        imu_latitudeAndLongitudeOutput tmp_latitudeAndLongitudeOutput(arr);
        imu_global::imu_latitudeAndLongitudeOutput_pack.lock.lock();
        imu_global::imu_latitudeAndLongitudeOutput_pack.data = tmp_latitudeAndLongitudeOutput;
        imu_global::imu_latitudeAndLongitudeOutput_pack.lock.unlock();
    } else if (arr.at(0) == 0x58) {
        imu_groundSpeed tmp_groundSpeed(arr);
        imu_global::imu_groundSpeed_pack.lock.lock();
        imu_global::imu_groundSpeed_pack.data = tmp_groundSpeed;
        imu_global::imu_groundSpeed_pack.lock.unlock();
    } else if (arr.at(0) == 0x59) {
        imu_quaternion tmp_quaternion(arr);
        imu_global::imu_quaternion_pack.lock.lock();
        imu_global::imu_quaternion_pack.data = tmp_quaternion;
        imu_global::imu_quaternion_pack.lock.unlock();
    } else {
        //do nothing
    }
}
